[SPARK-56167][PS] Align astype with pandas 3 default string behavior#54968
Closed
ueshin wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-56167][PS] Align astype with pandas 3 default string behavior#54968ueshin wants to merge 1 commit intoapache:masterfrom
ueshin wants to merge 1 commit intoapache:masterfrom
Conversation
Member
Author
zhengruifeng
approved these changes
Mar 24, 2026
HyukjinKwon
approved these changes
Mar 24, 2026
Member
|
Merged to master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR updates a few pandas-on-Spark
astypepaths to match pandas 3 behavior for the default string dtype.In pandas 3,
astype(str)returns the default string dtype and preserves missing values instead of converting them to string literals such as"NaN"or"<NA>". pandas-on-Spark still used the older behavior in a few localized conversion paths, including numeric, null, string, and boolean casts.This PR makes three small changes in
python/pyspark/pandas/data_type_ops/:astype(str)preserves missing values for pandas 3 string resultsastype(bool)resultWhy are the changes needed?
Without this change, several pandas-on-Spark
astypetests fail with pandas 3 because some conversion paths still follow the older string-casting behavior.The failures came from two related mismatches:
astype(str)converted missing values into string literals instead of preserving them as missing valuesThis patch fixes those localized mismatches while keeping the pandas 2 behavior unchanged.
Does this PR introduce any user-facing change?
Yes.
For pandas 3 users, pandas-on-Spark
astype(str)now preserves missing values in the affected paths instead of converting them to string literals. This also fixes related behavior for boolean and string-backed casts that depend on pandas 3's default string behavior.How was this patch tested?
The existing tests should pass.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)